package com.xyazm.product.service.impl;

import com.xyazm.common.utils.ParamCheckUtil;
import com.xyazm.product.dao.ProductSkuDAO;
import com.xyazm.product.domain.dto.ProductSkuDTO;
import com.xyazm.product.domain.entity.ProductSkuDO;
import com.xyazm.product.exception.ProductErrorCodeEnum;
import com.xyazm.product.mapstruct.ProductSkuApiMapstruct;
import com.xyazm.product.service.IProductSkuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商品sku信息
 * @author xuyou
 * @date 2022年05月15日 21:28
 */
@Slf4j
@Service
public class ProductSkuServiceImpl implements IProductSkuService {

    @Autowired
    private ProductSkuDAO productSkuDAO;

    @Override
    public ProductSkuDTO getProductSkuBySkuCode(String skuCode) {
        ParamCheckUtil.checkStringNonEmpty(skuCode, ProductErrorCodeEnum.SKU_CODE_IS_NULL);
        ProductSkuDO productSku = productSkuDAO.getProductSkuBySkuCode(skuCode);
        return ProductSkuApiMapstruct.INSTANCE.convertProductSkuDTO(productSku);
    }

    @Override
    public List<ProductSkuDTO> listProductSkusBySkuCode(List<String> skuCodeList) {
        ParamCheckUtil.checkCollectionNonEmpty(skuCodeList, ProductErrorCodeEnum.SKU_CODE_IS_NULL);
        List<ProductSkuDO> productSkuDOList = productSkuDAO.listProductSkusBySkuCode(skuCodeList);
        return ProductSkuApiMapstruct.INSTANCE.convertProductSkuDTOs(productSkuDOList);

    }
}
